package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyMovieListBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class MovieListAdapter extends StkProviderMultiAdapter<MyMovieListBean> {

    public MovieListAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new MovieListProvider());
    }

    private class MovieListProvider extends BaseItemProvider<MyMovieListBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_movie_list;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyMovieListBean bean) {
            if (bean.getListData() != null && bean.getListData().size() != 0) {
                baseViewHolder.getView(R.id.ivMovieListItemImg).setVisibility(View.VISIBLE);
                Glide.with(baseViewHolder.itemView).load(bean.getListData().get(0).getThumbUrl()).into((ImageView) baseViewHolder.getView(R.id.ivMovieListItemImg));
            } else {
                baseViewHolder.getView(R.id.ivMovieListItemImg).setVisibility(View.GONE);
            }
            baseViewHolder.setText(R.id.tvMovieListItemName, bean.getName());
            baseViewHolder.setText(R.id.tvMovieListItemSize, getContext().getString(R.string.content_num, bean.getListData().size()));
        }
    }

}
